package com.juqimiao.outposts.spring.oauth2.mobile.code;


import com.juqimiao.outposts.spring.oauth2.mobile.SecurityCodeGenerator;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

/**
 * 手机验证码生成器.
 * @author collin
 * @date 2018/4/3
 */
@Service
@Primary
public class MobileCodeGenerator implements SecurityCodeGenerator {

    private String code;

    /**
     * 获取一个验证码.
     * @return 验证码.
     */
    private String getCode(){
        return this.code;
    }

    /**
     * 设置一个验证码.
     * @param code 验证码.
     */
    private void setCode(String code){
        this.code = code;
    }

    /**
     * 比对外部提供的验证码是否有效.
     * @param presentCode 验证码.
     * @return 比对结果，true: 表示有效；false: 表示无效.
     */
    @Override
    public boolean validate(String presentCode) {
        return presentCode.equals(code);
    }

    /**
     * 产生一个验证码.
     * @return 验证码.
     */
    @Override
    public String generateCode() {
        return code = "123456";
    }

    /**
     * 获得一个空验证码.
     * @return 验证码.
     */
    @Override
    public String getNullCode() {
        return "N/A";
    }
}

